package com.hudilao.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hudilao.entity.Customer;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDate;

@Mapper
public interface CustomerMapper extends BaseMapper<Customer>{
    /**
     * 根据所获取的openid来查询用户
     * @param openid  用户唯一标识openid
     * @return openid对应用户
     */
    @Select("select * from customer where openid = #{openid}")
    Customer getByOpenid(String openid);

    /**
     * 根据openid
     * @param openid 用户唯一标识openid
     * @return 用户id
     */
    @Select("select id from customer where openid = #{openid}")
    Long getIdByOpenid(String openid);

    /**
     * 根据id查询用户
     * @param id 用户id
     * @return customer
     */
    @Select("select * from customer where id = #{id}")
    Customer getById(Long id);

    /**
     * 根据id更新用户信息
     * @param id  用户id
     * @param gender  性别
     * @param phoneNumber  手机号
     * @param birthdate  生日
     */
    @Update("update customer set gender = #{gender}, phone_number = #{phoneNumber}, birthdate = #{birthdate} WHERE id = #{id}")
    void updateCustomerInfo(Long id,
                           Integer gender,
                           String phoneNumber,
                           LocalDate birthdate);

    //void insert(Customer customer);
}
